﻿using CPPEI.BD.VMTool.Datas;
using CPPEI.BD.VMTool.Untils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CPPEI.BD.VMTool.Views
{
    /// <summary>
    /// SolutionConfigWindow.xaml 的交互逻辑
    /// </summary>
    public partial class SolutionConfigWindow : Window
    {
        public SolutionConfigWindow()
        {
            InitializeComponent();
            LoadVideoMatrixConfig();
        }

        private void _ctlAdd_Click(object sender, RoutedEventArgs e)
        {
            VideoMatrixWindow videoMatrixWindow = new VideoMatrixWindow();
            videoMatrixWindow.Closed += videoMatrixWindow_Closed;
            videoMatrixWindow.ShowDialog();
        }

        void videoMatrixWindow_Closed(object sender, EventArgs e)
        {
            LoadVideoMatrixConfig();
        }

        private void _ctlEdit_Click(object sender, RoutedEventArgs e)
        {
            if (_ctlDataGridSolution.SelectedItem != null)
            {
                Datas.Solution solution = _ctlDataGridSolution.SelectedItem as Datas.Solution;
                VideoMatrixWindow videoMatrixWindow = new VideoMatrixWindow(solution);
                videoMatrixWindow.Closed += videoMatrixWindow_Closed;
                videoMatrixWindow.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选择要编辑的信息！");
            }
        }

        private void _ctlDelete_Click(object sender, RoutedEventArgs e)
        {
            if (_ctlDataGridSolution.SelectedItem != null)
            {
                Datas.Solution solution = _ctlDataGridSolution.SelectedItem as Datas.Solution;
                if (VMSolutionUntil.DeleteSolution(solution))
                {
                    LoadVideoMatrixConfig();
                    MessageBox.Show("删除信息成功!");
                }
                else
                {
                    MessageBox.Show("删除信息失败!");
                }
            }
            else
            {
                MessageBox.Show("请选择要删除的信息！");
            }
        }

        private void _ctlSave_Click(object sender, RoutedEventArgs e)
        {

        }

        private void _ctlCanle_Click(object sender, RoutedEventArgs e)
        {

        }


        private void LoadVideoMatrixConfig()
        {
            _ctlDataGridSolution.ItemsSource = null;
            _ctlDataGridSolution.ItemsSource = null;
            List<Datas.Solution> ListSolution = VMSolutionUntil.GetAllSolution();
            if (ListSolution != null)
            {
                _ctlDataGridSolution.ItemsSource = ListSolution;

            }
         
        }

      

        private void _ctlDataGridSolution_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            var selectedItem = _ctlDataGridSolution.SelectedItem;
            Datas.Solution solution = selectedItem as Datas.Solution;
            if (solution != null)
            {
                _ctlDataGridVideMatrix.ItemsSource = solution.Mapping;
            }
            
        }
      
     
    }
}
